package com.service.weChatWifiLogin.service.impl;

import com.service.config.utils.IdUtil;
import com.service.weChatWifiLogin.entity.ConnectSuccessInfo;
import com.service.weChatWifiLogin.dao.ConnectSuccessInfoDao;
import com.service.weChatWifiLogin.service.ConnectSuccessInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 连接成功表(ConnectSuccessInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-01 11:40:58
 */
@Service("connectSuccessInfoService")
public class ConnectSuccessInfoServiceImpl implements ConnectSuccessInfoService {
    @Resource
    private ConnectSuccessInfoDao connectSuccessInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ConnectSuccessInfo queryById(String id) {
        return this.connectSuccessInfoDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ConnectSuccessInfo> queryAllByLimit(int offset, int limit) {
        return this.connectSuccessInfoDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param connectSuccessInfo 实例对象
     * @return 实例对象
     */
    @Override
    public ConnectSuccessInfo insert(ConnectSuccessInfo connectSuccessInfo) {
        this.connectSuccessInfoDao.insert(connectSuccessInfo);
        return connectSuccessInfo;
    }

    /**
     * 修改数据
     *
     * @param connectSuccessInfo 实例对象
     * @return 实例对象
     */
    @Override
    public ConnectSuccessInfo update(ConnectSuccessInfo connectSuccessInfo) {
        this.connectSuccessInfoDao.update(connectSuccessInfo);
        return this.queryById(connectSuccessInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.connectSuccessInfoDao.deleteById(id) > 0;
    }

    /***
     * 新增联网成功记录
     * @param id
     * @param shopId
     */
    @Override
    public void insertRecords(String id, String shopId) {
        ConnectSuccessInfo connectSuccessInfo = new ConnectSuccessInfo();
        connectSuccessInfo.setId(IdUtil.getStringId());
        connectSuccessInfo.setDate(new Date());
        connectSuccessInfo.setShopId(shopId);
        connectSuccessInfo.setTransactionalId(id);
        connectSuccessInfoDao.insert(connectSuccessInfo);
    }
}
